clear

local inputs_dir "C:\Users\yuxus\Dropbox\PROJECTS (ACTIVE)\Bond.Risk.Premia.Mitra.Xu\Data\PRIOR_TO_RFS_RR\combined_results_yu\data"

cd "C:\Users\yuxus\Dropbox\PROJECTS (ACTIVE)\Bond.Risk.Premia.Mitra.Xu\RFS manuscript and replication packet\replication\empirical results\Figure1_replication"

* plot 10-1 and 5-1 year slopes for both treasuries and TIPS

/* ----------------------------------------------------------------------------------------------------------------------------------------------------------
1. set up data
---------------------------------------------------------------------------------------------------------------------------------------------------------- */

cd "`outputs_dir'"

* gsw nominal bonds
use "`inputs_dir'\gsw_daily_ytm.dta"
// rename date dated
* convert to monthly, using month end prices
gen D = day(dated)
gen M = month(dated)
gen Y = year(dated)
gen datem = ym(Y,M)
format datem %tm
egen max_D = max(D), by(datem)
keep if D==max_D
gen nom_slope_10_1 = SVENY10 - SVENY01

keep datem nom_slope_10_1
drop if mi(nom_slope_10_1)
gen yyyymm = month(dofm(datem)) + 100*year(dofm(datem))
export excel yyyymm nom_slope_10_1 using "plot_nominal.xls", replace firstrow(var)


* gsw daily tips
use "`inputs_dir'\gsw_daily_tips.dta", clear

* drop days with missing yield curves
drop if mi(TIPSY02) | mi(TIPSY03) | mi(TIPSY04) | mi(TIPSY05)

* convert to monthly, using month end prices

gen D = day(dated)
gen M = month(dated)
gen Y = year(dated)
gen datem = ym(Y,M)
format datem %tm

egen max_D = max(D), by(datem)
keep if D==max_D

merge 1:1 datem using "TIPS_1Y_PROXY.dta"
drop _merge

merge 1:1 datem using "liq_adj_tips.dta"
drop _merge

/* ----------------------------------------------------------------------------------------------------------------------------------------------------------
2. construct variables
---------------------------------------------------------------------------------------------------------------------------------------------------------- */

local SHORT TIPS_1Y_MICH

gen tips_slope_10_1 = TIPSY10 - `SHORT'
replace tips_slope_10_1 = . if datem<ym(1999,1)

gen tips_liqadj_slope_10_1 = TIPS_LIQADJ_10y - `SHORT'
replace tips_liqadj_slope_10_1 = . if datem<ym(2004,1)

/* ----------------------------------------------------------------------------------------------------------------------------------------------------------
3. output data for plots in matlab
---------------------------------------------------------------------------------------------------------------------------------------------------------- */

gen yyyymm = month(dofm(datem)) + 100*year(dofm(datem))
export excel yyyymm tips_slope_10_1 tips_liqadj_slope_10_1 using "plot_tips.xls", replace firstrow(var)